package mao.sourcecode.threadlocal;

import java.util.concurrent.TimeUnit;

public class Consumer implements Runnable {
    private ThreadLocal<Integer> local;
    public Consumer(ThreadLocal<Integer> local) {
        this.local = local;
    }

    @Override
    public void run() {
        try {
            for (int i = 0; i < 10; i++) {
                TimeUnit.MICROSECONDS.sleep(1);
                local.set(local.get() + 1);
            }
            System.out.println(Thread.currentThread().getName()+" "+local.get());
        }catch (InterruptedException e){
            e.printStackTrace();
        }
    }
}
